package client.common;

import static client.common.libs.JQuery.$;
import static org.stjs.javascript.JSCollections.$array;
import static org.stjs.javascript.JSCollections.$castArray;

import org.stjs.javascript.Array;

import client.common.EndPoints.UserEP;
import client.common.Models.Persona;
import client.common.angular.NgScope;
import client.common.directives.EPChanging;
import client.common.javascript.JsConsole;
import client.common.javascript.JsProcedure1;
import enums.Sexo;
import enums.TipoDocumento;

@SuppressWarnings("unused")
public class FormularioPersonaScope extends NgScope {

	private Array<TipoDocumento> tiposDocumento;
	private Array<Sexo> sexos;
	private EPChanging epChanging;
	private UserEP User;
	private Persona persona;

	public static Array<String> $inject() {
		return $array("epChanging", "User");
	}

	public FormularioPersonaScope(EPChanging epChanging, UserEP User) {
		super("FormularioPersonaScope");
		this.epChanging = epChanging;
		this.User = User;

		this.tiposDocumento = $castArray(TipoDocumento.values());
		this.sexos = $castArray(Sexo.values());
	}

	public void buscarPersonas(String query,
			final JsProcedure1<Array<Persona>> callback) {
		User.getPersonasConDocumento(query, new JsProcedure1<Array<Persona>>() {
			public void $invoke(Array<Persona> data) {
				callback.$invoke(data);
			}
		});
	}

	public void valueSelected(Persona value) {
		JsConsole.console.log("valor seleccionado " + value);
		this.persona = value;

		$("#inputDocumento").attr("disabled", "disabled");
	}

	public void borrarPersonaSeleccionada() {
		this.persona = new Persona();
		$("#inputDocumento").removeAttr("disabled");
	}
}
